package com.dbq.fast.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.yiba.vpn.utils.Constants;

/**
 * Created by sunkai on 2017/6/17.
 */

public class SpUtil {
    private static Context sContext;

    private static SharedPreferences sp;

    private SpUtil() {

    }

    public static void init(Context context) {
        sContext = context;
        sp = context.getSharedPreferences(Constants.SharedPreferenceName, Context.MODE_PRIVATE);

    }

    public static String getString(String key) {
        return sp.getString(key, "");
    }

    public static void setString(String key, String value) {
        sp.edit().putString(key, value).apply();
    }

    public static boolean getBoolean(String key) {
        return getBoolean(key,false);
    }
    public static boolean getBoolean(String key,boolean boo) {
        return sp.getBoolean(key, boo);
    }

    public static void setBoolean(String key, boolean value) {
        sp.edit().putBoolean(key, value).apply();
    }

    public static int getInt(String key){
        return sp.getInt(key, 0);
    }

    public static int getInt(String key, int defaultVal){
        return sp.getInt(key, defaultVal);
    }

    public static void setInt(String key, int value){
        sp.edit().putInt(key, value).apply();
    }

    public static long getLong(String key){
        return sp.getLong(key, 0L);
    }

    public static long getLong(String key, long defaultVal){
        return sp.getLong(key, defaultVal);
    }

    public static void setLong(String key, long value){
        sp.edit().putLong(key, value).apply();
    }
}
